package com.zghhost.stockweb.commandline;

import com.zghhost.stockweb.entity.SinaDadanEntity;
import com.zghhost.stockweb.service.impl.SinaDadanService;
import com.zghhost.stockweb.util.DateUtil;
import com.zghhost.stockweb.util.DayUtil;
import com.zghhost.stockweb.util.NumberUtil;

import java.util.*;

/**
 * @author guohua.zhang@zhaopin.com.cn
 * @Date 2019/5/21 09:37
 */
public class ShishiDandanNDay {
    public static void main(String[] args)throws Exception{
        SinaDadanService sinaDadanService = new SinaDadanService();

        String code = "300010";

        if(code.startsWith("6")){
            code = "sh"+code;
        }else{
            code = "sz" + code;
        }

        Date[] days = DayUtil.dayWithoutWeekday(5);

        String sday,eday;
        for(Date day : days){
            try{
                sday = eday = DateUtil.parseDateToStr(day,DateUtil.DATE_FORMAT_YYYY_MM_DD);

                List<SinaDadanEntity> sinaDadanEntities =  sinaDadanService.getDayRangeDadan(code,sday,eday);

                Map<String,Double[]> map = new HashMap<String,Double[]>();

                for(SinaDadanEntity sinaDadanEntity : sinaDadanEntities){
                    if(map.get(sinaDadanEntity.getKind()) == null){
                        map.put(sinaDadanEntity.getKind(),new Double[]{0D,0D,0D,0D,0D});
                    }
                    map.get(sinaDadanEntity.getKind())[0] = map.get(sinaDadanEntity.getKind())[0] + sinaDadanEntity.getPrice();
                    map.get(sinaDadanEntity.getKind())[1] = map.get(sinaDadanEntity.getKind())[1] + sinaDadanEntity.getVolume();
                    map.get(sinaDadanEntity.getKind())[2] = map.get(sinaDadanEntity.getKind())[2] + (sinaDadanEntity.getVolume()*sinaDadanEntity.getPrice());
                    map.get(sinaDadanEntity.getKind())[4] = map.get(sinaDadanEntity.getKind())[4] + 1;
                }

                Double[] U = map.get("U");
                Double[] D = map.get("D");

                System.out.println(sday);

                System.out.println("U: "+U[1]+" "+ NumberUtil.formatNum(""+U[2],false)+" "+(U[2]/U[1])+" "+(U[1]/U[4]));

                System.out.println("D: "+D[1]+" "+NumberUtil.formatNum(""+D[2],false)+" "+(D[2]/D[1])+" "+(D[1]/D[4]));

                System.out.println();

                if(day != days[days.length-1]){
                    Thread.sleep(1675);
                }
            }catch (Exception e){

            }
        }
    }
}
